package org.ourgrid.acceptance.aggregator;

import static org.junit.Assert.assertFalse;

import org.junit.Test;
import org.ourgrid.acceptance.util.aggregator.Req_602_Util;
import org.ourgrid.acceptance.util.aggregator.Req_603_Util;
import org.ourgrid.aggregator.AggregatorComponent;
import org.ourgrid.aggregator.AggregatorConstants;
import org.ourgrid.reqtrace.ReqTest;

public class Req_603_Test extends AggregatorAcceptanceTestCase {

	private Req_602_Util req_602_Test = new Req_602_Util(getComponentContext());
	private Req_603_Util req_603_Test = new Req_603_Util(getComponentContext());

	/*
	 * Create an Aggregator;
	 * Start an Aggregator with the correct public key "publicKey1";
	 * Stop the Aggregator with the public key "wrongPublicKey" - Verify if the following warn message was logged:
     *    1. An unknown entity tried to stop the Aggregator. Only the local modules can perform this operation. Unknown entity public key: [senderPublicKey].
	 *
	 */
	@ReqTest(test = "AT-603.1", reqs = "stop component - wrong public key")
	@Test public void test_AT_603_1_StopAggregatorWithWrongPublicKey() throws Exception {
		
		//Create an Aggregator;
		//Start an Aggregator
		AggregatorComponent component = req_602_Test.startAggregator();
		
		//Stop the Aggregator with the public key "wrongPublicKey"
		req_603_Test.stopAggregatorWithWrongPublicKey(component, "wrongPublicKey");
		
	}
	
	/*
	 * Create an Aggregator;
	 * Start an Aggregator
	 * Stop the Aggregator with the correct public key;
	 * Verify if the following remote objects are NOT bound:
     *     o AGGREGATOR_OBJECT
     *     o AGGREGATOR_DS_MONITOR_OBJECT
	 * Verify if the ControlClient received the operation succeed message.
	 *
	 */
	@ReqTest(test = "AT-603.2", reqs = "stop component")
	@Test public void test_AT_603_2_StopAggregator() throws Exception {

		//Create an Aggregator;
		//Start an Aggregator
		AggregatorComponent component = req_602_Test.startAggregator();
		
		//Stop the Aggregator with the correct public key;
		//Verify if the ControlClient received the operation succeed message.
		req_603_Test.stopAggregator(component);
		
		// Verify if AGGREGATOR_OBJECT is NOT bound
		assertFalse(isBound(component, AggregatorConstants.OBJECT_NAME));
		
		// Verify if AGGREGATOR_DS_MONITOR_OBJECT is NOT bound
		assertFalse(isBound(component, AggregatorConstants.DS_MONITOR_OBJECT_NAME));

	}
}
